/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Vista;

import Validacion.ValidaCliente;
import java.awt.event.ItemEvent;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import Modelo.Cliente;
import Validacion.ValidaReVoluntaria;
import javax.swing.JPanel;

/**
 *
 * @author bastian
 */
public class Panel_ReVoluntaria extends javax.swing.JPanel {

    /**
     * Creates new form Panel_Cliente
     */
    public Panel_ReVoluntaria() {
        initComponents();
    }
    
    private VentanaPrincipal V_Principal;
    private Panel_ResumenRecepcion P_Resumen;
    
    public void setFrame(JFrame f){
        this.V_Principal= (VentanaPrincipal) f;
    }
    
    public void setPanel_ResumenRecepcion(JPanel p){
        P_Resumen = (Panel_ResumenRecepcion)p;
    }
        
    private void Limpiar(){
        this.TextField_ID.setText("");
        this.TextField_RUT.setText("");
        this.jTextField_Nombre.setText("");
        this.jTextField_Descripcion.setText("");
        this.jDateChooser_Fecha.setDate(null);
    }
    
    public ArrayList getDatos(){
        ArrayList datos = new ArrayList();
        
        datos.add(this.TextField_ID.getText());
        datos.add(this.jDateChooser_Fecha.getDate());
        datos.add(this.jTextField_Descripcion.getText());
        datos.add(this.TextField_RUT.getText());
        
        return datos;
    }
    
    protected void ReVoluntariaNueva(boolean b){
        this.Limpiar();
        this.TextField_ID.setEditable(b);
        this.jButton_BuscarRec.setVisible(!b);
        this.jButton_ModificarRec.setVisible(!b);
        this.jDateChooser_Fecha.setDate(new java.util.Date());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        TextField_RUT = new javax.swing.JTextField();
        jTextField_Nombre = new javax.swing.JTextField();
        jDateChooser_Fecha = new com.toedter.calendar.JDateChooser();
        jLabel_Nombre = new javax.swing.JLabel();
        TextField_ID = new javax.swing.JTextField();
        Label_RUT = new javax.swing.JLabel();
        jButton_BuscarRUT = new javax.swing.JButton();
        jLabel_Descripcion = new javax.swing.JLabel();
        jTextField_Descripcion = new javax.swing.JTextField();
        jButton_Cancelar = new javax.swing.JButton();
        jLabel_ReVoluntaria = new javax.swing.JLabel();
        jButton_ModificarRec = new javax.swing.JButton();
        Label_ID = new javax.swing.JLabel();
        jLabel_FeIngreso = new javax.swing.JLabel();
        jButton_BuscarRec = new javax.swing.JButton();
        label_Justicia481 = new Vista.Imagenes_Label.justicia.Label_Justicia48();
        jButton_AgregarProductos = new javax.swing.JButton();

        setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        setMaximumSize(new java.awt.Dimension(1000, 550));
        setMinimumSize(new java.awt.Dimension(1000, 550));
        setName("Cliente");
        setPreferredSize(new java.awt.Dimension(1000, 550));

        TextField_RUT.setEditable(false);
        TextField_RUT.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        TextField_RUT.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                TextField_RUTKeyTyped(evt);
            }
        });

        jTextField_Nombre.setEditable(false);
        jTextField_Nombre.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N

        jDateChooser_Fecha.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jDateChooser_Fecha.setMaxSelectableDate(new java.util.Date(253370779303000L));
        jDateChooser_Fecha.setMinSelectableDate(new java.util.Date(1262318503000L));
        jDateChooser_Fecha.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jDateChooser_FechaKeyTyped(evt);
            }
        });

        jLabel_Nombre.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel_Nombre.setText("Nombre");

        TextField_ID.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        TextField_ID.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                TextField_IDKeyTyped(evt);
            }
        });

        Label_RUT.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        Label_RUT.setText("RUT");

        jButton_BuscarRUT.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jButton_BuscarRUT.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Vista/Imagenes_Files/buscar/24.png"))); // NOI18N
        jButton_BuscarRUT.setText("Buscar");
        jButton_BuscarRUT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_BuscarRUTActionPerformed(evt);
            }
        });

        jLabel_Descripcion.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel_Descripcion.setText("Descripcion");

        jTextField_Descripcion.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N

        jButton_Cancelar.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jButton_Cancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Vista/Imagenes_Files/cruz/24.png"))); // NOI18N
        jButton_Cancelar.setText("Cancelar");
        jButton_Cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_CancelarActionPerformed(evt);
            }
        });

        jLabel_ReVoluntaria.setFont(new java.awt.Font("Arial", 0, 36)); // NOI18N
        jLabel_ReVoluntaria.setText("Recepcion Voluntaria");

        jButton_ModificarRec.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jButton_ModificarRec.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Vista/Imagenes_Files/modificar/documentos/24.png"))); // NOI18N
        jButton_ModificarRec.setText("Modificar");

        Label_ID.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        Label_ID.setText("ID Recepción");

        jLabel_FeIngreso.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel_FeIngreso.setText("Fecha Ingreso");

        jButton_BuscarRec.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jButton_BuscarRec.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Vista/Imagenes_Files/buscar/24.png"))); // NOI18N
        jButton_BuscarRec.setText("Buscar");

        jButton_AgregarProductos.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jButton_AgregarProductos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Vista/Imagenes_Files/producto/24.png"))); // NOI18N
        jButton_AgregarProductos.setText("Añadir Productos");
        jButton_AgregarProductos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_AgregarProductosActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(jButton_AgregarProductos, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButton_Cancelar))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel_ReVoluntaria)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 596, Short.MAX_VALUE)
                                .addComponent(label_Justicia481, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel_FeIngreso)
                                .addGap(10, 10, 10)
                                .addComponent(jDateChooser_Fecha, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(Label_RUT)
                                .addGap(83, 83, 83)
                                .addComponent(TextField_RUT, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButton_BuscarRUT))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(Label_ID)
                                .addGap(18, 18, 18)
                                .addComponent(TextField_ID, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(26, 26, 26)
                                .addComponent(jButton_BuscarRec)
                                .addGap(6, 6, 6)
                                .addComponent(jButton_ModificarRec))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(jLabel_Descripcion)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jTextField_Descripcion, javax.swing.GroupLayout.PREFERRED_SIZE, 494, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(jLabel_Nombre)
                                    .addGap(54, 54, 54)
                                    .addComponent(jTextField_Nombre, javax.swing.GroupLayout.PREFERRED_SIZE, 496, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(186, 186, 186))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_ReVoluntaria)
                    .addComponent(label_Justicia481, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 97, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(Label_ID))
                    .addComponent(TextField_ID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton_BuscarRec)
                    .addComponent(jButton_ModificarRec))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(jLabel_FeIngreso))
                    .addComponent(jDateChooser_Fecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(40, 40, 40)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_Descripcion)
                    .addComponent(jTextField_Descripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(7, 7, 7)
                        .addComponent(Label_RUT))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(TextField_RUT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButton_BuscarRUT))
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(jLabel_Nombre))
                    .addComponent(jTextField_Nombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(102, 102, 102)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_Cancelar)
                    .addComponent(jButton_AgregarProductos))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_BuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_BuscarActionPerformed
        // TODO add your handling code here:
        V_Principal.addPanel_Busqueda_Cliente(1);
    }//GEN-LAST:event_jButton_BuscarActionPerformed

    private void TextField_RUTKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TextField_RUTKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_TextField_RUTKeyTyped

    private void jDateChooser_FechaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jDateChooser_FechaKeyTyped
        // TODO add your handling code here:
        char c = evt.getKeyChar();
        if (!Character.isDigit(c) && c != '-') {
            evt.consume();
        }
    }//GEN-LAST:event_jDateChooser_FechaKeyTyped

    private void TextField_IDKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TextField_IDKeyTyped
        // TODO add your handling code here:
        char c = evt.getKeyChar();

        if (!Character.isDigit(c) || this.TextField_ID.getText().length() > 10) {
            evt.consume();
        }
    }//GEN-LAST:event_TextField_IDKeyTyped

    private void jButton_CancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_CancelarActionPerformed
        // TODO add your handling code here:
        this.Limpiar();
        V_Principal.desbloquearPanel();
        V_Principal.removePanel(this);
        V_Principal.addPanel_Bienvenido();
    }//GEN-LAST:event_jButton_CancelarActionPerformed

    private void jButton_AgregarProductosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_AgregarProductosActionPerformed
        // TODO add your handling code here:
        if(ValidaReVoluntaria.ReVoluntariaValida(this.getDatos())){
            this.P_Resumen.LaRecepcion = this.getDatos();
            this.P_Resumen.esVoluntaria();
            this.P_Resumen.Inicializar();
            this.V_Principal.addPanel_ResumenRecepcion(false);
            V_Principal.bloquearPanel();
        }
        
        else
            JOptionPane.showMessageDialog(V_Principal, "Datos Incorrectos", "Error", JOptionPane.ERROR_MESSAGE);
    }//GEN-LAST:event_jButton_AgregarProductosActionPerformed

    private void jButton_BuscarRUTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_BuscarRUTActionPerformed
        // TODO add your handling code here:
        V_Principal.addPanel_Busqueda_Cliente(1);
        V_Principal.bloquearPanel();
        
    }//GEN-LAST:event_jButton_BuscarRUTActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel Label_ID;
    private javax.swing.JLabel Label_RUT;
    private javax.swing.JTextField TextField_ID;
    protected javax.swing.JTextField TextField_RUT;
    private javax.swing.JButton jButton_AgregarProductos;
    private javax.swing.JButton jButton_BuscarRUT;
    private javax.swing.JButton jButton_BuscarRec;
    private javax.swing.JButton jButton_Cancelar;
    private javax.swing.JButton jButton_ModificarRec;
    private com.toedter.calendar.JDateChooser jDateChooser_Fecha;
    private javax.swing.JLabel jLabel_Descripcion;
    private javax.swing.JLabel jLabel_FeIngreso;
    private javax.swing.JLabel jLabel_Nombre;
    private javax.swing.JLabel jLabel_ReVoluntaria;
    private javax.swing.JTextField jTextField_Descripcion;
    protected javax.swing.JTextField jTextField_Nombre;
    private Vista.Imagenes_Label.justicia.Label_Justicia48 label_Justicia481;
    // End of variables declaration//GEN-END:variables
}
